1291C - Mind Control - CodeForces Solution


brute force data structures greedy math *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;

void solve(){
	int n, m, k;
	cin>>n>>m>>k;
	k = min(k, m-1);
	int res = 0;
	vector<int> a(n+2), v(m+1);
	for(int i = 1; i <= n; ++i){
		cin>>a[i];
	}
	
	for(int i = 1; i <= m; ++i){
		v[i] = max(a[i], a[n - m + i]);
		//cout<<v[i]<<' ';
		//cout<<i<<' '<<n - m + i<<endl;
	}
	
	//cout<<endl;

	vector<vector<int> > b(m+1, vector<int>(m+1));
	for(int i = 1; i <= m; ++i){
		int cur_min = INT_MAX;
		for(int j = i; j <= m; ++j){
			cur_min = min(cur_min, v[j]);
			b[i][j] = cur_min;
			//cout<<cur_min<<' ';
		}
		//cout<<endl;
	}
	
	for(int i = 0; i <= k+1; ++i){
		for(int j = 1; j <= i; ++j){
			res = max(res, b[j][m - i + j]);
			//cout<<j<<' '<<m-i +j<<endl;
		}
		//cout<<endl;
	}
	//*/
	cout<<res<<'\n';
	return;
}

int main() {
	int t; cin>>t;
	while(t--)solve();
	return 0;
}


Comments

Submit
0 Comments
More Questions

761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme
1195A - Drinks Choosing
5D - Follow Traffic Rules
1272A - Three Friends
1632D - New Year Concert
1400D - Zigzags
716C - Plus and Square Root
412A - Poster
844B - Rectangles
1591A - Life of a Flower
1398C - Good Subarrays
629A - Far Relative’s Birthday Cake
1166A - Silent Classroom
1000B - Light It Up
218B - Airport
1463B - Find The Array
1538C - Number of Pairs
621B - Wet Shark and Bishops
476B - Dreamoon and WiFi
152C - Pocket Book
1681D - Required Length
1725D - Deducing Sortability
1501A - Alexey and Train